var companyId = sessionStorageUtils.getJson(storageKey.sessionStorageKey.companyId);
var schoolId = sessionStorageUtils.getJson(storageKey.sessionStorageKey.schoolId);
var schoolMap = sessionStorageUtils.getJson(storageKey.sessionStorageKey.schoolMap);

var app = new Vue({
    el: '#app',
    data: {
        info: {},
        conversation: [],
        permissions: ['']
    },
    filters: {
        formatDate(time) {
            // time = time * 1000;
            let date = new Date(time);
            return formatDateTime(date)
        }
    },
    //进入页面初始化方法
    created: function () {
        var that = this;
        var token = sessionStorageUtils.getJson(storageKey.sessionStorageKey.token);
        if (empty(token)) {
            layer.msg("<span style='color:red'>登录超时！请重新登录！</span>", {time: 1500, icon: 5});
            setTimeout(function () {
                window.location.href = _LOGIN_PAGE;
            }, 1200);

            return;
        }
        that.getInfo();
        that.getConversation();
    },
    methods: {
        //权限控制
        permission: function (index) {
            return (_PERMISSIONS.indexOf(this.permissions[index]) != -1);
        },
        // 得到预约信息
        getInfo: function () {
            var that = this;
            var url = _HOST + _API.user_orderInfo_getById + "?id=" + aGET.id;
            Get(that, url)
                .then(function (response) {
                    // 响应成功回调
                    console.log(response);
                    if (response) {
                        that.info = response.data;
                    }
                });
        },
        // 得到会话列表
        getConversation: function () {
            var that = this;
            var url = _HOST + _API.user_message_selectCommentByRelationIdAndType + "?relationId=" + aGET.id + "&type=3,5"+"&companyId="+companyId;
            Get(that, url)
                .then(function (response) {
                    // 响应成功回调
                    console.log(response);
                    if (response) {
                        that.conversation = response.result;
                    }
                });
        },
        // send发送消息
        send: function () {
            var that = this;
            layer.open({
                type: 1,
                content: $('#select')
            });
        },
        sendMsg: function () {
            var content = $("#content").val();
            var type = $("#type").val();
            var trackTime = $("#trackTime").val();
            var relationId = aGET.relationId;
            console.log(content);
            console.log(type);
            console.log(trackTime);
            console.log(relationId);
            if (empty(content)) {
                layer.msg('内容不能为空！', {time: 1500, icon: 5});
                return;
            }
            if (empty(type)) {
                layer.msg('请选择类型！', {time: 1500, icon: 5});
                return;
            }
            if (empty(trackTime)) {
                layer.msg('请选择下次回访时间！', {time: 1500, icon: 5});
                return;
            }
            var that = this;
            var param = {};
            param['content'] = content;
            param['type'] = type;
            param['trackTime'] = trackTime;
            param['relationId'] = relationId;
            //console.log(param)
            Post(that, _HOST + _API.user_orderTrackRelation_sendVisitMsg, param, false)
                .then(function (response) {
                    // 响应成功回调
                    console.log(response);
                    if (response) {
                        if (response.success) {
                            layer.msg(response.msg, {time: 1500, icon: 1});
                            setTimeout(function () {
                                window.parent.location.reload(); //刷新父页面
                                layer.closeAll();
                            }, 1500)
                        } else {
                            layer.msg(response.msg, {time: 1500, icon: 5});
                        }
                    }
                    $("#Form").data('bootstrapValidator').destroy();
                    $('#Form').data('bootstrapValidator', null);
                    Validator();
                })
        }
    },
});
